Repository navigation
fix(Comments): Mark as resolved and Reopen hand focus to the replacing control in the comment header - #14155
fix(Comments): Mark as resolved and Reopen hand focus to the replacing control in the comment header#14155cixzhang wants to merge 3 commits into
Conversation
…that replaces them Resolving a thread replaces Mark as resolved with Reopen, and reopening it replaces Reopen with Mark as resolved, when the host's update arrives. The pressed control left the page, so keyboard focus fell to the page body. Both controls now take one ref from Core's focus hand-off, useFocusAcrossSwap: when the pressed control leaves while it has focus, the control that replaces it takes focus, unless focus has moved somewhere else. A failed request replaces nothing. OverflowList renders an inert copy of each action to measure it, so the hand-off ignores an element while it is inside an inert region. It reads inertness when it records or takes a hand-off, not when the element attaches, because a region can stop being inert later. Core's internal entry re-exports the hook for Lab. Cherry-picked from #13737 (by @ernestt). Co-authored-by: Ernest Tien <ernesttien@meta.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
Approved pending CI. CI has not run on this head yet: it runs once the draft is marked ready for review.
The fix reads correctly: with the hook skipping inert elements, OverflowList's measuring copy no longer clears or takes the hand-off, so the visible Reopen or Mark as resolved receives focus, and the six existing Core callers each own their hook instance, so they see no change. That comes from reading the code; the new tests contain each case but did not run in this review.
- Non-blocking: the
useFocusAcrossSwap.tsheader grows to 19 lines with a 28-word sentence; a short comment besideisInertCopywould keep the header near the usual 12 lines (inline suggestion).
Claims and files checked
Review mode: full; reason: no-earlier-review
Claims:
- Title: Mark as resolved and Reopen hand focus to the control that replaces them. Verified by reading: one ref serves both controls (
CommentRow.tsx:381-399,CommentActions.tsx:415,:428), and the hook records at detach and hands over at attach (useFocusAcrossSwap.ts:83-113). The test "hands focus to Reopen after a keyboard resolve, and back after Reopen" contains the case; not run here. - Base drops focus to the page body after either press. Reported (your Chromium run); consistent with base, where the inert measuring copy, which commits first, takes the hand-off.
- OverflowList renders each action twice, an inert copy first, so the copy's ref ran first. Verified:
OverflowList.tsx:415-431,:457-463. - Item, Pagination, Token, TreeList and NavMenu headings already use the hook. Verified:
Item.tsx:679,Pagination.tsx:424,TokenFocusHandoff.tsx:51-54,TreeListItem.tsx:448,NavHeadingMenuItem.tsx:174(Button uses it too). - Focus that the viewer moved elsewhere before the host's update stays there. Verified by reading
useFocusAcrossSwap.ts:100-101(a hand-off is recorded only while the control owns focus); the test "leaves focus where the viewer moved it when the host resolves later" contains it. - A failed request moves no focus. Verified by reading: a failure only records an error and swaps no control (
CommentsContext.tsx,runCommentAction), and a busy button stays the same element witharia-disabled(Button.tsx:1148,:1180). - The hook ignores an element inside an inert region for both recording and taking, and reads inertness at each hand-off. Verified:
useFocusAcrossSwap.ts:39-41,:83,:99; the two new hook tests contain both cases. - Core's other callers see no change. Verified by enumeration: a repository search for the hook finds six Core callers and Comments; each Core caller creates the hook for the one element it renders, and an inert element can hold no focus.
- The internal touch entry re-exports the hook beside its focus helpers, outside the public API. Verified:
touch.ts:93-98,:133;packages/core/package.jsonexports unchanged; the hook is in no public index;touch.test.tsandtouch-support-bundle.test.mjsassert it. - Comments keeps no focus state of its own for this. Verified: the only addition is the one hook call (
CommentRow.tsx:381). - No public API, visual or other behavior change. Verified within the diff and the direct importers of the changed modules.
- The native-disabled half of the audit item is already fixed on main. Verified: Button renders
aria-disabled(Button.tsx:1148,:1180). - The Comments docs promise that focus never drops to the page. Verified:
Comments.doc.mjs:156on main. - The focus record asks the component's record to name the destination, and Comments has no record yet. Verified: the record's FR4 text; no Comments record on main.
- Changeset: the hand-off ignores inert elements, the internal entry re-exports it, Lab's Comments carries focus, it is not public API, and apps see no change. Verified, by the evidence above.
- Scope: Comments and CommentThread. Verified: CommentThread renders CommentRow (
CommentThread.tsx:188). - Overlap with #13737 and #11392. Verified: #13737 is the open original; #11392 changes only Link files.
- Test runs (138 passed), typecheck, lint, formatting,
review:pre, the changeset check, the real-Chromium results, the red-first failures and the validation on an older main. Reported; none ran here, and CI has not run at this head.
Files:
.changeset/comments-resolve-focus-handoff.md: clearpackages/core/src/internal/touch.ts: clearpackages/core/src/internal/touch.test.ts: clearpackages/core/src/utils/useFocusAcrossSwap.ts: non-blocking header notepackages/core/src/utils/useFocusAcrossSwap.test.tsx: clearpackages/lab/src/Comments/CommentActions.tsx: clearpackages/lab/src/Comments/CommentRow.tsx: clearpackages/lab/src/Comments/Comments.test.tsx: clearscripts/touch-support-bundle.test.mjs: clear
|
/approve-spec 27fc502 |
…e-focus-handoff # Conflicts: # packages/core/src/utils/useFocusAcrossSwap.ts
|
/approve-spec a3ca6a9 |
There was a problem hiding this comment.
Approved pending CI. CI's test and build jobs are still running on this head; they must pass before merge.
Reproduced locally in Chromium: on main, Enter on Mark as resolved or on Reopen leaves focus on the page body; on this head focus moves to Reopen, then back to Mark as resolved, with the focus ring. The new tests pass here, the new Comments and hook tests fail without the change, and the seven Core callers of the hook keep passing their tests.
- Non-blocking: the
useFocusAcrossSwap.tsheader is now 17 lines and its added sentence runs 28 words; a short comment besideisInertCopywould keep the header near 12 lines (inline suggestion).
Claims and files checked
Review mode: full; reason: merge-touches-pr-files
Claims:
- Title: Mark as resolved and Reopen hand focus to the control that replaces them. Verified: reproduced locally in Chromium on the Lab Comments Panel story (focus on Reopen, then on Mark as resolved); the new Comments test passes.
- Before the change, focus falls to the page body after either press. Verified: reproduced locally on the base in Chromium; the new Comments test fails there.
- The Comments docs promise that focus never drops to the page. Verified:
Comments.doc.mjs:156. - Every other panel action keeps focus. Reported (behavior of the base).
- OverflowList renders an inert measuring copy first, and that copy's ref cleared or took the hand-off. Verified:
OverflowList.tsx:415-431renders the inert copy before the visible list; with the base's hook under this head's Comments change, focus still falls to the body in Chromium (reproduced locally). - Item, Pagination, Token, TreeList and NavMenu headings already use the hook. Verified by a repository search (Button and Link use it too).
- When the pressed control leaves while it has focus, its replacement takes focus. Verified, as for the title.
- Focus that the viewer moved elsewhere before the host's update stays there. Verified: the test "leaves focus where the viewer moved it when the host resolves later" passes; a hand-off is recorded only while the control owns focus (
useFocusAcrossSwap.ts:114-117). - A failed request moves no focus. Verified by reading: a failure only records an error (
CommentsContext.tsx:365-376), and a busy control stays the same element witharia-disabled(Button.tsx:1145,:1177). - The hook ignores an element inside an inert region, and reads inertness each time it records or takes a hand-off. Verified:
useFocusAcrossSwap.ts:37-39,:98,:114; both new hook tests pass, and the inert-copy test fails without the change (run locally). - The focus record's FR4 asks the component's record to name the destination, and Comments has no record. Verified: the FR4 text; no Comments record on main. The draft record for the move to Core is not in the repository (reported).
- The native-disabled half of the audit item is already fixed on main. Verified: Button renders
aria-disabled(Button.tsx:1145,:1177). - Comments keeps no focus state of its own. Verified: one hook call (
CommentRow.tsx:381). - An element in an inert region holds no focus, so Core's other callers see no change. Verified: a repository search finds seven Core files that call the hook, each for the element it renders; their 25 test files pass locally.
- The internal touch entry re-exports the hook beside its focus helpers, outside the public API, with a
[chore] Internal:changeset. Verified:touch.ts:99-103,:131-133; the API report lists no change (run locally); the changeset check passes locally. - No public API, visual or other behavior change beyond the fix. Verified within the diff and the direct importers of the changed modules.
- Link arrives as a new caller in #11392 with no hook change. Verified: #11392 is now on main; it added the sibling
focusTargetWithinexport and rewrote the file header, and left the hook's logic unchanged. - Scope: Comments and CommentThread. Verified: CommentThread renders CommentRow (
CommentThread.tsx:188). - A cherry-pick of #13737 with a co-author credit, with the ref directly on the buttons since #14106. Verified: the commit's co-author trailer;
CommentActions.tsx:415,:428. - Test runs (138 and 96 passing, the bundle test 16/16, the callers' 39 files), install, build, typecheck, formatting, lint, and the real-Chromium runs on main and this head. Reported; the Comments, hook, internal entry, bundle and caller tests also pass locally, and CI's typecheck and lint pass at this head.
- "Keeps the handoff for a control first mounted inside an inert region" fails when inertness is read only at attach. Reported (an intermediate version; the test passes on the base and on this head).
- Changeset: the hand-off ignores inert elements, the internal entry re-exports it, Comments carries focus from Mark as resolved to Reopen and back, it is not public API, and apps see no change. Verified, by the evidence above.
- Overlap with #13735 to #13739. Reported.
Files:
.changeset/comments-resolve-focus-handoff.md: clearpackages/core/src/internal/touch.test.ts: clearpackages/core/src/internal/touch.ts: clearpackages/core/src/utils/useFocusAcrossSwap.test.tsx: clearpackages/core/src/utils/useFocusAcrossSwap.ts: non-blocking header notepackages/lab/src/Comments/CommentActions.tsx: clearpackages/lab/src/Comments/CommentRow.tsx: clearpackages/lab/src/Comments/Comments.test.tsx: clearscripts/touch-support-bundle.test.mjs: clear
| * An element inside an inert region, such as the copy OverflowList renders to | ||
| * measure its items, can hold no focus, so it neither leaves nor takes a | ||
| * handoff. Inertness is read when a handoff is recorded or taken, not when the | ||
| * node attaches: a region can stop being inert later. |
There was a problem hiding this comment.
Non-blocking (source comments): the header is now 17 lines, and this sentence runs 28 words over two topics. A short comment beside the helper keeps the header near 12 lines:
// An inert element cannot hold focus. It records and takes no handoff.
// OverflowList renders an inert copy of each item to measure it.
// Read inertness at each handoff. A region can stop being inert later.
function isInertCopy(value: unknown): boolean {The helper matches any element in an inert region, not only a copy, so isInInertRegion would also fit.
There was a problem hiding this comment.
Changes requested. The hand-off works when Reopen fits in the comment header, but the title, the description and the release note claim it in every case.
- Miss: The title, the description's "When the pressed control leaves the page while it has focus, the control that replaces it takes focus" and "for Mark as resolved and Reopen, it is the control that replaces it", and the changeset's "carries focus from Mark as resolved to Reopen and back" are false where the header fits the Mark as resolved icon but not the wider Reopen button (the Margin Comment story, or the Panel at about 400 px), because Reopen then collapses into the more menu and focus falls to the page body, so either send focus to the more-menu trigger in that case, with a test at such a width, or bound those four places to a replacement that fits in the header.
Reproduced locally in Chromium on this head, where CI passes: in the Margin Comment story focus reaches Reopen, then lands on the page body when Reopen collapses; at full width it stays on Reopen. The earlier non-blocking note on the useFocusAcrossSwap.ts file header still applies.
Claims and files checked
Review mode: same-head; reason: none
Title (live): fix(Comments): Mark as resolved and Reopen hand focus to the control that replaces them
changed rules (3): Claim bounding in one round; Read the bound a claim already carries; For a claim about focus, events or DOM placement
- Claim bounding in one round: finding above, applied to the title, the Problem and solution fit sentence, the Expected behavior sentence and the changeset.
- Read the bound a claim already carries: checked the title, every description section and the changeset; the Evidence and Testing results are bounded by their own Panel-story lead-in, so they are not reported.
- For a claim about focus, events or DOM placement: finding above (a replacement hidden in the more menu); checked and not falsifying: a click that leaves the button unfocused (no hand-off, outside "while it has focus"), SVG controls (none), same-origin frames and Picture-in-Picture (the helpers are realm-safe), shadow roots (both copies share one tree), a control disabled while busy (same element), a covering surface or a pick from the more menu (focus stays with them; run locally), a caller focus target (none), the thread component and the Core callers.
Claims:
- Title: the two controls hand focus to their replacement. False where Reopen collapses into the more menu (run locally); verified where it fits (run locally; the new Comments test passes in CI).
- Cherry-pick of an earlier pull request with a co-author credit; the ref sits directly on the two buttons. Verified: commit trailer;
CommentActions.tsx:415,:428. - Before the change, a keyboard user loses focus to the page body after either press. Reported (base behavior; the earlier review of this head reproduced it in Chromium).
- The pressed button unmounts when the host flips the resolved state and nothing moves focus. Verified by reading the base.
- The Comments docs promise focus never drops to the page. Verified:
Comments.doc.mjs:156. Every other panel action keeps focus: reported. - OverflowList renders an inert measuring copy first, whose ref cleared or took the hand-off. Verified:
OverflowList.tsx:415-431; the earlier review of this head ran the head with the base's hook and saw focus on the body. - Item, Pagination, Token, TreeList and NavMenu headings already use the hook. Verified: a search of the whole head tree (Button and Link use it too).
- When the pressed control leaves while it has focus, its replacement takes focus. False where Reopen collapses (focus reaches Reopen, then the body); verified where it fits.
- Focus the viewer moved elsewhere stays there. Verified: the test "leaves focus where the viewer moved it when the host resolves later" passes in CI; a hand-off is recorded only while the control owns focus (
useFocusAcrossSwap.ts:114-117). - A failed request moves no focus. Verified by reading: a failure only records an error, and a busy control stays the same element with
aria-disabled. - The hook ignores an element inside an inert region and reads inertness each time it records or takes a hand-off. Verified:
useFocusAcrossSwap.ts:37-39,:98,:114; both new hook tests pass in CI. - For these two controls, the focus destination is the control that replaces them. False where Reopen collapses.
- Comments has no record, and a draft record names this destination. Verified no record; the draft is not in the repository (reported).
- The native-disabled half of the audit item is already fixed. Verified: Button renders
aria-disabled. - Comments keeps no focus state of its own. Verified: one hook call (
CommentRow.tsx:381). - An element in an inert region holds no focus, so Core's other callers see no change. Verified: the search lists seven Core files, each owning one element; their tests pass in CI.
- The internal touch entry re-exports the hook outside the public API, with an internal changeset. Verified:
touch.ts:131-133; CI's API delta lists no change. - No public API, visual or other behavior change beyond the fix. Verified within the diff and the direct importers of the changed modules.
- Results before and after the change in Chromium, the branded Chrome stills, and the earlier captures. Reported; consistent with the full-width run here.
- The new tests fail without the fix, and the inert-region test fails when inertness is read only at attach. Reported; the earlier review of this head ran the first three red against the base or the base's hook.
- Scope: Comments and CommentThread, and the listed Core files. Verified: CommentThread renders CommentRow; the file list matches the diff.
- Other callers keep their behavior, and their test, browser and Button swap results. Verified for the callers by the search and CI; the counts and browser runs are reported.
- Install, build, typecheck, formatting, lint, changeset check and test counts at this head. Verified by CI's typecheck, lint, build and test jobs at this head; the counts are reported.
- Changeset: the hand-off ignores inert elements and the internal entry re-exports it (verified), Comments carries focus from Mark as resolved to Reopen and back (false where Reopen collapses), not public API and apps see no change (verified).
- Overlap with other pull requests. Reported.
Files:
.changeset/comments-resolve-focus-handoff.md: finding (release note claim)packages/core/src/internal/touch.test.ts: clearpackages/core/src/internal/touch.ts: clearpackages/core/src/utils/useFocusAcrossSwap.test.tsx: clearpackages/core/src/utils/useFocusAcrossSwap.ts: non-blocking header notepackages/lab/src/Comments/CommentActions.tsx: finding (Reopen can collapse after the hand-off)packages/lab/src/Comments/CommentRow.tsx: clearpackages/lab/src/Comments/Comments.test.tsx: clear (no test at a collapsing width)scripts/touch-support-bundle.test.mjs: clear
| ) : resolveAction?.kind === 'reopen' ? ( | ||
| <Button | ||
| key="reopen" | ||
| ref={resolveAction.controlRef} |
There was a problem hiding this comment.
Miss: this ref hands focus to Reopen, but Reopen (75 px) is wider than the Mark as resolved icon (28 px). OverflowList has no minimum and remeasures when the key changes, so in a narrow header Reopen moves into the more menu one commit later and focus falls to the page body (reproduced locally in the Margin Comment story). The more-menu trigger already keeps focus when the action is picked from the menu, so it is a natural target for that case.
…ontrol while it shows in the header
|
/approve-spec 23aa309 |
There was a problem hiding this comment.
Changes requested. The hand-off works wherever Reopen fits in the comment header, and the title, the solution sentence and the release note now say so; one description sentence still claims it everywhere.
- Miss: The description's Expected behavior bullet, "for Mark as resolved and Reopen, it is the control that replaces it", is still unbounded and is false in a narrow comment such as the Margin Comment story, where Reopen collapses into the more menu and focus ends on the page body (as your Known gap paragraph says), so give it the same bound as the title, for example "it is the control that replaces it while that control shows in the comment's header".
Reproduced locally in Chromium: on the Panel story focus moves to Reopen and back, while on the base it drops to the page body, and the new tests pass locally and fail against the base. Heavy CI is deferred on this head. The earlier non-blocking note on the useFocusAcrossSwap.ts file header still applies.
Claims and files checked
Review mode: incremental; reason: none
changed rules (0): none
Title (live): fix(Comments): Mark as resolved and Reopen hand focus to the replacing control in the comment header
Claims:
- Title: the two controls hand focus to the replacing control in the comment header. Verified: run locally on the Panel story; the new Comments test passes locally.
- Cherry-pick with a co-author credit; the ref sits directly on the two buttons. Verified: commit trailer;
CommentActions.tsx:415,:428. - Before the change, a keyboard user loses focus to the page body after either press. Verified for Mark as resolved (run locally on the base); reported for Reopen.
- The pressed button unmounts when the host flips the resolved state, and nothing moves focus. Verified: base code and the red-first run.
- The Comments docs promise focus never drops to the page. Verified:
Comments.doc.mjs, Focus after changes. Every other panel action keeps focus: reported. - OverflowList's inert measuring copy took the same ref first and cleared or took the hand-off. Verified:
OverflowList.tsx:415-431; this head with the earlier hook leaves focus on the body in Chromium, and the hook's inert-copy test fails on it. - Item, Pagination, Token, TreeList and NavMenu headings already use the hook. Verified: a repository search (Button and Link use it too).
- When the pressed control leaves while focused, its replacement takes focus while it shows in the header. Verified: run locally on the Panel story.
- Focus the viewer moved elsewhere stays there. Verified: the test passes locally; a hand-off is recorded only while the control owns focus (
useFocusAcrossSwap.ts:114-117). - A failed request moves no focus. Verified by reading: no optimistic swap, a failure records an error, and a busy control stays the same element.
- Known gap: in a narrow comment Reopen collapses and focus falls to the page body, as on the base. Verified: run locally on both trees, identical end frames.
- A follow-up tracks the narrow case. Unverified: no matching issue found; not a behavior claim.
- The hook ignores an element inside an inert region and reads inertness each time it records or takes a hand-off. Verified:
useFocusAcrossSwap.ts:37-39,:98,:114; both new hook tests pass, and each fails against a mutant of its case. - Expected behavior: for these two controls the focus destination is the control that replaces them. False in a narrow comment (finding above).
- Comments has no record; a draft record names the destination. No record verified; the draft is not in the repository (unverified).
- The native-disabled half of the audit item is already fixed. Verified: Button uses
aria-disabled. - Comments shares one ref and keeps no focus state of its own. Verified: one hook call (
CommentRow.tsx:381). - An element in an inert region holds no focus, so Core's other callers see no change. Verified: the search lists seven Core callers, each owning one element; their 20 test files (919 tests) pass locally.
- The internal touch entry re-exports the hook outside the public API, with an internal changeset. Verified:
touch.ts:131-133; the API generator lists no change. - No public API, visual or other behavior change beyond the fix. Verified within the diff and the direct importers of the changed modules.
- Before and after browser results, the Chrome stills and the earlier captures. Reported; consistent with the local runs (the stills name the previous head, whose code matches this one apart from the release note).
- The new tests fail without the fix, and the inert-region test fails when inertness is read only at attach. Verified: red-first and mutant runs, locally.
- Scope: Comments, CommentThread and the listed Core files. Verified: CommentThread renders CommentRow; the file list matches the diff.
- Other callers' test counts, the Link browser specs and the Button swap run. Reported; the callers' unit tests pass locally.
- Install, build, typecheck, formatting, lint, changeset check and test counts at this head. Reported; typecheck and lint pass in CI, the bundle test (16/16) and the Comments tests pass locally.
- Release note: the inert skip and the internal re-export (verified), Comments carries focus while the replacing control shows in the header (verified), not public API and apps see no change (verified).
- Overlap with other pull requests. Reported.
Files:
.changeset/comments-resolve-focus-handoff.md: clear (now bounded)packages/core/src/internal/touch.test.ts: clearpackages/core/src/internal/touch.ts: clearpackages/core/src/utils/useFocusAcrossSwap.test.tsx: clearpackages/core/src/utils/useFocusAcrossSwap.ts: non-blocking header notepackages/lab/src/Comments/CommentActions.tsx: clear (the narrow-header collapse is a stated, inherited gap)packages/lab/src/Comments/CommentRow.tsx: clearpackages/lab/src/Comments/Comments.test.tsx: clearscripts/touch-support-bundle.test.mjs: clear
Cherry-picked from #13737 by @ernestt, who wrote this fix; the commit credits @ernestt with a
Co-authored-byline. This team pull request carries it onto currentmain. One adaptation: main's #14106 removed theCommentActionSlotwrappers around the comment actions, so the hand-off ref now sits directly on the Mark as resolvedIconButtonand the ReopenButton.User impact
A keyboard user who presses Mark as resolved, or Reopen, loses focus to the page body. Resolving replaces Mark as resolved with Reopen, and reopening does the reverse, when the host's update arrives. The pressed control leaves the page, and focus goes with it. The user must tab from the top of the page back to the thread.
Problem and solution fit
Why does focus drop? The pressed button unmounts when the host flips
isResolved, and nothing moves focus to the control that replaces it.Why does it harm the task? Resolve and reopen are the last step of reviewing a thread. Losing focus after them breaks the keyboard path through the panel, and a screen reader announces nothing useful.
Why does it matter? The Comments docs promise "Focus never drops to the page", and every other action in the panel keeps it.
Why could Core's hand-off not serve as it stood? OverflowList renders each action twice: an inert copy to measure it, then the visible one. Both copies take the same ref, and the copy's ref detaches and attaches first, so it cleared or took the hook's hand-off before the visible replacement mounted.
Mark as resolved and Reopen now take one ref from Core's focus hand-off,
useFocusAcrossSwap, which Item, Pagination, Token, TreeList and NavMenu headings already use when React replaces a focused element. When the pressed control leaves the page while it has focus, the control that replaces it takes focus, while that control shows in the comment's header. If the viewer has moved focus elsewhere by the time the host's update arrives, focus stays where they put it. A failed request replaces nothing, so focus does not move.Known gap, kept from
main: in a narrow comment, such as the Margin Comment story, OverflowList collapses Reopen into the More menu. The control that replaces Mark as resolved is then not in the header, so focus still falls to the page body, as onmain. A follow-up tracks moving focus to a visible control there. The hook now ignores an element while it is inside an inert region, and it reads inertness each time it records or takes a hand-off, not once when the element attaches.Expected behavior and authority
spec:AST-085FR4 (when a component removes a focused control, the component names where focus goes): for Mark as resolved and Reopen, it is the control that replaces it while that control shows in the comment's header. When Reopen collapses into the More menu, focus still falls to the page (the Known gap above). Comments has no record in Lab; the draft record that comes with its move to Core names this destination.mainin Chromium before this change: after Enter on Mark as resolved, and after Enter on Reopen, the active element is the body. The other half of that BLOCK, native-disabled buttons, is already fixed onmain, since Core Button usesaria-disabled.Smallest restoration
useFocusAcrossSwapref. Comments keeps no focus state of its own.useFocusAcrossSwapignores an element while it is inside an inert region, such as OverflowList's measuring copy: that element neither records a hand-off nor takes one. The hook reads inertness when it records a hand-off and when it takes one, not when the element attaches, so a control first mounted inside an inert region, such as a link row in a covered BottomSheet, keeps its hand-off once the region is live again. An element in an inert region can hold no focus, so Core's other callers see no change.@astryxdesign/core/internal/touchentry re-exports the hook for Astryx's own packages, beside the focus helpers it already carries for Lab (isFocusLost,focusForLastInput). It is outside the public API (spec:AST-017FR21). A[chore] Internal:changeset names it.No public API, visual, or other behavior change.
Evidence
Comments.test.tsx, "hands focus to Reopen after a keyboard resolve, and back after Reopen", which fails without the fix, and "leaves focus where the viewer moved it when the host resolves later"; inuseFocusAcrossSwap.test.tsx, "carries focus to the visible replacement past an inert copy of the element", which fails without the inert skip, and "keeps the handoff for a control first mounted inside an inert region", which fails when inertness is read only when the element attaches.The captures below come from the first version of this fix, which kept its own hand-off in Comments. #13737's head gave the same result in the same story (the run above).
Branded Chrome stills at this head
Google Chrome 158.0.8127.89 on macOS, in a one-off public Actions run. It built Storybook at this head (
23aa309e) and at its merge base withmain(8204874b), and drove the Lab/Comments panel story with the keyboard: Tab, focus "Mark as resolved", Enter, then Enter again. It used DPR 2 and reduced motion. The active element is recorded beside each frame.8204874b)Scope
Components: Comments, CommentThread.
Core files:
packages/core/src/utils/useFocusAcrossSwap.tsanduseFocusAcrossSwap.test.tsx,packages/core/src/internal/touch.tsandtouch.test.ts,scripts/touch-support-bundle.test.mjs, and the changeset.changeset/comments-resolve-focus-handoff.md.Other callers of
useFocusAcrossSwapThis pull request changes the hook's inert-copy guard. The hook now ignores an element while it is inside an inert region, and reads inertness when it records or takes a hand-off. Its other callers keep their behavior: an element inside an inert region can hold no focus, so nothing they render ever went through that path.
hreffallback) and Link (the same pattern; both now resolve their focus target throughfocusTargetWithin, which fix(Link): preserve focus when becoming disabled #11392 added beside the hook), Pagination (its swap control), Item, Token, TreeList and NavMenu headings.useFocusAcrossSwap.test.tsx(11/11, both inert-copy cases included),internal/touch, and fix(Link): preserve focus when becoming disabled #11392's Link cases, which exercisefocusTargetWithin, included.Link.a11y.chromium.spec.ts, with fix(Link): preserve focus when becoming disabled #11392's disabled-swap cases, 14/14.mainand this head are identical (re-run at this head). While disabled, focus stays on the fallback<button>"Docs" (aria-disabled="true"); re-enabled, it goes back to<a href="#docs">.Testing
useFocusAcrossSwap,internal/touchandtouch-support-bundlepassed (138 tests), and real Chromium on a static Storybook build.tsc(core, lab),prettier,eslintandcheck:changesetsall pass;touch-support-bundle16/16;main, Mark as resolved sends focus to<body>, and Reopen does too;Overlap checked: #13737 (the original by @ernestt; this team pull request replaces it on current main), #13736, #13738, #13739, #13735 (separate: ernestt's other Comments fixes and the CommentPin move), #11392 (Link's focus fix: a new useFocusAcrossSwap caller, no hook change; whichever lands second merges main)